package com.hzpd.hainan.module.news.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzpd.hainan.R;
import com.hzpd.hainan.app.ListBaseAdapter;
import com.hzpd.hainan.model.news.NewsBean;
import com.hzpd.hainan.utils.LogUtils;
import com.hzpd.hainan.utils.TUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 猪猪侠 on 2017/7/3.
 */

public class NewsItemListViewAdapterNew extends BaseMultiItemQuickAdapter<NewsBean,BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public NewsItemListViewAdapterNew(List<NewsBean> data) {
        super(data);
        addItemType(NewsBean.THREEPIC,R.layout.news_3_item_layout);
        addItemType(NewsBean.LEFTPIC,R.layout.news_list_item_layout);
        addItemType(NewsBean.NOPIC,R.layout.news_list_item_nopic_layout);
        addItemType(NewsBean.BIGPIC,R.layout.news_list_bigitem_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, NewsBean item) {
        switch (helper.getItemViewType()){
            case NewsBean.THREEPIC://三联图
                helper.addOnClickListener(R.id.newsItem_root);
                helper.setText(R.id.newsitem_title,item.getTitle());
                helper.setText(R.id.news_3_tv_time,item.getUpdateTime());//更新时间
                helper.setText(R.id.praisenumber_id,item.getPraisenum());//赞数量
                helper.setText(R.id.viewnumber__id,item.getViewnum());//浏览量
                helper.getView(R.id.nli_foot).setVisibility(View.VISIBLE);
                helper.addOnClickListener(R.id.lose_interest_id);
                List<String> imgs = item.getImgs();
                if (imgs!=null&&imgs.size()>0){
                    Glide.with(mContext).load(imgs.get(0)).crossFade().placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.news_3_item1));
                    if (imgs.size()>1){
                        Glide.with(mContext).load(imgs.get(1)).crossFade().placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.news_3_item2));
                        if (imgs.size()>2){
                            Glide.with(mContext).load(imgs.get(2)).crossFade().placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.news_3_item3));
                        }
                    }
                }
                if (item.getIstop()!=null&&item.getIstop().equals("1")){
                    helper.setImageResource(R.id.nli_foot,R.drawable.list_special);
                }else if(item.getVoteflag()!=null&&item.getVoteflag().equals("1")){
                    helper.setImageResource(R.id.nli_foot,R.drawable.list_vote);
                }else if ("4".equals(item.getRtype())){
                    helper.setImageResource(R.id.nli_foot,R.drawable.zq_subscript_special);
                }else{
                    helper.getView(R.id.nli_foot).setVisibility(View.GONE);
                }

                break;
            case NewsBean.LEFTPIC:
                helper.addOnClickListener(R.id.newsItem_root);
                helper.setText(R.id.newsitem_title,item.getTitle());
                helper.setText(R.id.newsitem_copyfrom,item.getCopyfrom());
                helper.setText(R.id.praisenumber_id,item.getPraisenum());
                helper.setText(R.id.viewnumber__id,item.getViewnum());
//                helper.setText(R.id.newsitem_time,item.getUpdateTime());
                helper.getView(R.id.newsitem_img).setVisibility(View.VISIBLE);
                helper.getView(R.id.nli_foot).setVisibility(View.GONE);
                helper.getView(R.id.nli_foot).setVisibility(View.VISIBLE);
                helper.addOnClickListener(R.id.lose_interest_id);
                if ("1".equals(item.getType())){
                    helper.getView(R.id.newsitem_img).setVisibility(View.GONE);
                }

                if (item.getIstop()!=null&&item.getIstop().equals("1")){
                    helper.setImageResource(R.id.nli_foot,R.drawable.list_special);
                }else if(item.getVoteflag()!=null&&item.getVoteflag().equals("1")){
                    helper.setImageResource(R.id.nli_foot,R.drawable.list_vote);
                }else if ("4".equals(item.getRtype())){
                    helper.setImageResource(R.id.nli_foot,R.drawable.zq_subscript_special);
                }else{
                    helper.getView(R.id.nli_foot).setVisibility(View.GONE);
                }
                if (helper.getView(R.id.newsitem_img).getVisibility() == View.VISIBLE
                        && null != item.getImgs()
                        && item.getImgs().size() > 0) {
                    Glide.with(mContext).load(item.getImgs().get(0)).crossFade()
                            .placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.newsitem_img));
                } else {
                    Glide.with(mContext).load("").crossFade()
                            .placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.newsitem_img));
                }
                break;

            case NewsBean.NOPIC:
                helper.addOnClickListener(R.id.newsItem_root);
                helper.setText(R.id.newsitem_title,item.getTitle());
                helper.setText(R.id.newsitem_copyfrom,item.getCopyfrom());
                helper.setText(R.id.praisenumber_id,item.getPraisenum());
                helper.setText(R.id.viewnumber__id,item.getViewnum());
//                helper.setText(R.id.newsitem_time,item.getUpdateTime());
                helper.getView(R.id.nli_foot).setVisibility(View.GONE);
                helper.getView(R.id.nli_foot).setVisibility(View.VISIBLE);
                helper.addOnClickListener(R.id.lose_interest_id);
                //置顶 ,投票,专题
                if (item.getIstop()!=null&&item.getIstop().equals("1")){
                    helper.setImageResource(R.id.nli_foot,R.drawable.list_special);
                }else if(item.getVoteflag()!=null&&item.getVoteflag().equals("1")){
                    helper.setImageResource(R.id.nli_foot,R.drawable.list_vote);
                }else if ("4".equals(item.getRtype())){
                    helper.setImageResource(R.id.nli_foot,R.drawable.zq_subscript_special);
                }else{
                    helper.getView(R.id.nli_foot).setVisibility(View.GONE);
                }

                break;
            case NewsBean.BIGPIC:
                helper.addOnClickListener(R.id.newsItem_root);
                helper.setText(R.id.newsitem_title,item.getTitle());
                helper.setText(R.id.newsitem_copyfrom,item.getCopyfrom());
                helper.setText(R.id.praisenumber_id,item.getPraisenum());
                helper.setText(R.id.viewnumber__id,item.getViewnum());
//                helper.setText(R.id.newsitem_time,item.getUpdateTime());
                helper.getView(R.id.newsitem_img).setVisibility(View.VISIBLE);
                helper.getView(R.id.nli_foot).setVisibility(View.GONE);
                helper.getView(R.id.nli_foot).setVisibility(View.VISIBLE);
                helper.addOnClickListener(R.id.lose_interest_id);
                if ("1".equals(item.getType())){
                    helper.getView(R.id.newsitem_img).setVisibility(View.GONE);
                }

                if (item.getIstop()!=null&&item.getIstop().equals("1")){
                    helper.setImageResource(R.id.nli_foot,R.drawable.list_special);
                }else if(item.getVoteflag()!=null&&item.getVoteflag().equals("1")){
                    helper.setImageResource(R.id.nli_foot,R.drawable.list_vote);
                }else if ("4".equals(item.getRtype())){
                    helper.setImageResource(R.id.nli_foot,R.drawable.zq_subscript_special);
                }else{
                    helper.getView(R.id.nli_foot).setVisibility(View.GONE);
                }
                if (helper.getView(R.id.newsitem_img).getVisibility() == View.VISIBLE
                        && null != item.getImgs()
                        && item.getImgs().size() > 0) {
                    Glide.with(mContext).load(item.getImgs().get(0)).crossFade()
                            .placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.newsitem_img));
                } else {
                    Glide.with(mContext).load("").crossFade()
                            .placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.newsitem_img));
                }
                break;
        }
    }
}
